#!/usr/bin/python

from Load import Load
import pygame as p
from Tools import *

rotated=0

def darenzheshi(data:Load,screen:p.Surface,textx:str,w=854,h=480):
    target=show_school_map(data=data,screen=screen,w=w,h=h)
    black=data.color['text_black']
    back=data.color['title_background']
    name=data.vanilla['generals'][data.vanilla['player']['copy']-1]['name']
    text=data.version_font.render(name+'大人，这里是'+textx,True,(black[0],black[1],black[2]),(back[0],back[1],back[2]))
    text_rect=text.get_rect()
    text_rect.centerx=w//2
    text_rect.bottom=h//24*23
    screen.blit(text,text_rect)
    return target
def bushiniddipan(data:Load,screen:p.Surface,w=854,h=480):
    target=show_school_map(data=data,screen=screen,w=w,h=h)
    black=data.color['text_black']
    back=data.color['title_background']
    text=data.version_font.render("这不是你的地盘！",True,(black[0],black[1],black[2]),(back[0],back[1],back[2]))
    text_rect=text.get_rect()
    text_rect.centerx=w//2
    text_rect.bottom=h//24*23
    screen.blit(text,text_rect)
    return target
def show_school_map(data:Load,screen:p.Surface,w=854,h=480):
    background=p.transform.scale(data.screen3,(w,h))
    screen.blit(background,(0,0))

    locations=((w//17,h//2),(w//8*3,h//8),(w//8*3,h//16*5),(w//4,h//2),(w//16*3,h//16*11),(w//2,h//4),(w//16*7,h//2),(w//16*9,h//16*11),(w//8*7,h//10),(w//4*3,h//4),(w//4*3,h//2),(w//16*15,h//16*5))
    locates=data.vanilla['locates']

    red_rect=data.red_flag.get_rect()
    blue_rect=data.blue_flag.get_rect()
    white_rect=data.white_flag.get_rect()

    rects=list()
#    flags=list()
    cache:p.Rect

    for i in range(12):
        print("its ok in ",locates[i]['name'])
        print("the rect is",locations[i])
        if(locates[i]['zhengying']==None):
            cache=white_rect
            cache.center=locations[i]
            cache1=white_rect
            cache1.center=locations[i]
            rects.append(cache1)
            screen.blit(data.new_white(),cache)
#            if hblit[0]:
#                cache1=rectMove(blitRect[0],cache)
#                flags.append(
#                white.scroll(cache1[0],cache1[1])
#                )
#            else:
#                screen.blit(white,cache)
#                flags.append(None)
#                hblit[0]=True
#                blitRect[0]=cache
        if(locates[i]['zhengying']==True):
            cache=blue_rect
            cache.center=locations[i]
            cache1=blue_rect
            cache1.center=locations[i]
            rects.append(cache1)
            print('new item in rects. it\'s',cache.center)
            screen.blit(data.new_blue(),cache)
#            if hblit[1]:
#                cache1=rectMove(blitRect[1],cache)
#                flags.append(
#                blue.scroll(cache1[0],cache1[1])
# # )
#            else:
#                screen.blit(blue,cache)
#                flags.append(None)
#                hblit[1]=True
#                blitRect[1]=cache
        if(locates[i]['zhengying']==False):
            cache=red_rect
            cache.center=locations[i]
            cache1=red_rect
            cache1.center=locations[i]
            rects.append(cache1)
            print(cache is rects[i])
            screen.blit(data.new_red(),cache)
#            if hblit[2]:
#                cache1=rectMove(blitRect[2],cache)
#                flags.append(
#                red.scroll(cache1[0],cache1[1])
#                    )
#            else:
#                screen.blit(red,cache)
#                flags.append(None)
#                hblit[2]=True
#                blitRect[2]=cache
#    del cache
#    for i in range(12):
#        if flags[i]!=None:screen.blit(flags[i],rects[i])
    return locations

def show_choosing_zhengying(data:Load,screen:p.Surface,w=854,h=480):
    fore_color=data.color['title_orange']
    back_color=data.color['title_background']

    title=data.title_font.render("选择阵营",True,(fore_color[0],fore_color[1],fore_color[2]),(back_color[0],back_color[1],back_color[2]))
    title_rect=title.get_rect()
    title_rect.centerx=w//2
    title_rect.top=h//48

    school=p.transform.scale(data.school,(h//25*8,h//5*2))
    school_rect=school.get_rect()
    school_rect.left=w//2+w//10
    school_rect.top=title_rect.bottom+h//48

    qiyijun=p.transform.scale(data.qiyijun,(h//25*8,h//5*2))
    qiyi_rect=qiyijun.get_rect()
    qiyi_rect.right=w//2-w//10
    qiyi_rect.top=title_rect.bottom+h//48

    screen.fill((back_color[0],back_color[1],back_color[2]))
    screen.blit(title,title_rect)
    screen.blit(school,school_rect)
    screen.blit(qiyijun,qiyi_rect)
    return (school_rect,qiyi_rect)
def show_screen1(data:Load,screen:p.Surface,w=854,h=480,rotatedd=False):
    color=data.color
    fore_color=color['title_orange']
    back_color=color['title_background']
    comment_color=color['comment_grey']

    title=data.title_font.render("学校大作战",True,(fore_color[0],fore_color[1],fore_color[2]),(back_color[0],back_color[1],back_color[2]))
    title_rect=title.get_rect()
    title_rect.centerx=w//2
    title_rect.top=h//48

    version=data.version_font.render("骨灰级破解版",True,(fore_color[0],fore_color[1],fore_color[2]),(back_color[0],back_color[1],back_color[2]))
    global rotated
    version_roted:p.Surface
    if rotatedd:
        version_roted=p.transform.rotate(version,rotated)
        rotated+=1
    else:
        version_roted=version
    version_rect=version_roted.get_rect()
    version_rect.top=title_rect.bottom+h//48
    version_rect.left=w//48

    comment:p.Surface
    if rotatedd:
        comment=data.comment_font.render("觉得卡？点此关闭动画",True,(comment_color[0],comment_color[1],comment_color[2]),(back_color[0],back_color[1],back_color[2]))
    else:
        comment=data.comment_font.render("点此开启动画",True,(comment_color[0],comment_color[1],comment_color[2]),(back_color[0],back_color[1],back_color[2]))
    comment_rect=comment.get_rect()
    comment_rect.bottom=h//16*15
    comment_rect.right=w//16*15

    screen.fill((back_color[0],back_color[1],back_color[2]))
    fore_color=color['button_ty_blue']
    back_color=color['button_ty_white']

    load_old_version=data.version_font.render("加载存档",True,(fore_color[0],fore_color[1],fore_color[2]),(back_color[0],back_color[1],back_color[2]))
    lov_rec=load_old_version.get_rect()
    lov_rec.bottom=h-h//30
    lov_rec.right=w//2-w//10

    new_version=data.version_font.render("创建新档",True,(fore_color[0],fore_color[1],fore_color[2]),(back_color[0],back_color[1],back_color[2]))
    nv_rec=new_version.get_rect()
    nv_rec.bottom=h-h//30
    nv_rec.left=w//2+w//10

    screen.blit(title,title_rect)
    screen.blit(version_roted,version_rect)
    screen.blit(comment,comment_rect)
    screen.blit(load_old_version,lov_rec)
    screen.blit(new_version,nv_rec)

    return (lov_rec,nv_rec,comment_rect)